<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../common/base_body_header.jsp" %>
<%@include file="../common/navbar.jsp" %>
<%@include file="../common/page_content_pre.jsp" %>

<div class="page-content">
    <div class="row">
        <shiro:hasPermission name="sys:course:edit">
            <div class="col-sm-12">
                <button class="btn btn-xs btn-success" id="add_btn">
                    添加
                    <i class="icon-plus align-top bigger-125 icon-on-right"></i>
                </button>
            </div>
        </shiro:hasPermission>
        <div class="col-xs-12">
            <%--<form class="form-horizontal" role="form" action="${GLOBAL.basePath}/integral/list" method="post">--%>
            <%--<fieldset>--%>
            <%--<div class="form-group">--%>
            <%--<label class="col-sm-1 control-label" for="integralType">积分类型</label>--%>
            <%--<input type="hidden" name="userId" value="${integral.createUser}">--%>
            <%--<div class="col-sm-2">--%>
            <%--<select class="form-control" id="integralType" name="integralType">--%>
            <%--<option value="">全部</option>--%>
            <%--<option value="1">新增的积分</option>--%>
            <%--<option value="2">兑换的积分</option>--%>
            <%--</select>--%>
            <%--</div>--%>
            <%--<div class="col-sm-2">--%>
            <%--<button class="btn btn-primary btn-sm" onsubmit="return false;">--%>
            <%--查询--%>
            <%--<i class="icon-search align-top bigger-125 icon-on-right"></i>--%>
            <%--</button>--%>
            <%--</div>--%>
            <%--</div>--%>
            <%--</fieldset>--%>
            <%--</form>--%>
        </div>
        <div class="col-xs-12">
            <div class="table-responsive">
                <table id="list-table" class="table table-striped table-bordered table-hover" width="100%">
                    <thead>
                    <tr>
                        <th style="text-align:center;">课程名</th>
                        <th style="text-align:center;">课程级别</th>
                        <th style="text-align:center;">总课时</th>
                        <th style="text-align:center;">当前课程</th>

                        <th style="text-align:center;">
                            <i class="icon-time bigger-110 hidden-480"></i>添加时间
                        </th>
                        <th style="text-align:center;">操作</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
</div>

<%@include file="../common/page_content_suf.jsp" %>
<%@include file="../common/script.jsp" %>

<script type="text/javascript">

    var integralListTable;

    jQuery(function ($) {

        $("#add_btn").on("click", function () {
            addClick();
        });

        $('.date-picker').datepicker({autoclose: true}).next().on(ace.click_event, function () {
            $(this).prev().focus();
        });

        integralListTable = $('#list-table').dataTable({
            "sAjaxSource": "${GLOBAL.basePath}/course/asynList",
            "fnServerData": function (sSource, aDataSet, fnCallback) {
                $.ajax({
                    "dataType": 'json',
                    "type": "POST",
                    "url": sSource,
                    "data": aDataSet,
                    "success": fnCallback,
                    "beforeSend": function (XMLHttpRequest) {
                        layer.load();
                    },
                    "complete": function (XMLHttpRequest, textStatus) {
                        layer.closeAll('loading');
                    }
                });
            },
            "fnServerParams": function (aoData) {//向服务器传额外的参数
                <c:if test="${not empty aoData}">
                aoData.push(${aoData});
                </c:if>
            },
            "bSort": false,
            "bFilter": false,
            "bServerSide": true,
            "bProcessing": false,
            "bLengthChange": false,
            "bSearching": false,
            "sProcessing": "${GLOBAL.staticImagePath}/loading.gif' />",
            "oLanguage": {
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条",
                "sInfoEmpty": "No data"
            },
            "aoColumns": [
                {"mDataProp": "coursName", "sWidth": "300px"},
                {"mDataProp": "level", "sWidth": "180px"},
                {"mDataProp": "count", "sWidth": "180px"},
                {"mDataProp": "courseNumber", "sWidth": "150px"},
                {"mDataProp": "createTime", "sWidth": "180px"},
                {
                    "mDataProp": "id", "sWidth": "150px", "mRender": function (data, type, full) {

                    return "<div class='visible-md visible-lg hidden-sm hidden-xs btn-group'>"
                            + "<button class='football-edit btn btn-xs btn-info' pkId='" + data + "' style='margin-left:10px;' onclick='detailClick(this)'>"
                            + "详情"
                            + "</button>"
                            + "</div>"
                            + "<shiro:hasPermission name='sys:course:delete'><button class='football-del btn btn-xs btn-danger' pkId='" + data + "' onclick='delClick(this)'>"
                            + "<i class='icon-trash bigger-120'></i>"
                            + "</button></shiro:hasPermission>";
                }
                }
            ]
        });
    });

    var addClick = function () {
        document.location.href = "${GLOBAL.basePath}/course/add";
    };

    var detailClick = function (obj) {
        document.location.href = "${GLOBAL.basePath}/course/detail?courId=" + $(obj).attr("pkId");
    }

    var delClick = function (obj) {
        layer.confirm("确定要删除该课程？", {
            title: '提示',
            btn: ['确认', '取消'], //按钮
            area: ['auto', 'auto'] //宽高
        }, function () {
            var result = ART.mAjax("${GLOBAL.basePath}/course/delete", "POST", {id: $(obj).attr("pkId")});
            layer.alert("删除成功", {icon: 1, title: '提示', btn: ['OK']});
            integralListTable.fnDraw();
        })
    }
</script>
